package org.easyway.tiles.generic;

import java.io.File;
import java.io.FilenameFilter;

import javax.swing.filechooser.FileFilter;


public class ImageFileFilter extends FileFilter implements FilenameFilter {
	public boolean accept(File f) {
        if (f.isDirectory()) {
            return true;
        }
        
        //JPEG, GIF, BMP, PCX, PNG, IFF, RAS, PBM, PGM, PPM and PSD
        
        String extension = Utils.getExtension(f);
        if (extension == null)
        	return false;
        if(extension.equals("jpg"))
        	return true;
        if(extension.equals("jepg"))
        	return true;
        if(extension.equals("gif"))
        	return true;
        if(extension.equals("png"))
        	return true;
        if(extension.equals("pcx"))
        	return true;
        if(extension.equals("iff"))
        	return true;
        if(extension.equals("ras"))
        	return true;
        if(extension.equals("pbm"))
        	return true;
        if(extension.equals("pgm"))
        	return true;
        if(extension.equals("ppm"))
        	return true;
        if(extension.equals("psd"))
        	return true;
        if(extension.equals("bmp"))
        	return true;
        
        return false;
    }
	
	public boolean accept(File directory, String filename) {
		
		String extension = Utils.getExtension(filename);
        if(extension==null)
        	return false;
		if(extension.equals("jpg"))
        	return true;
        if(extension.equals("jepg"))
        	return true;
        if(extension.equals("gif"))
        	return true;
        if(extension.equals("png"))
        	return true;
        if(extension.equals("tiff"))
        	return true;
        if(extension.equals("bmp"))
        	return true;
		 
        return false;
	}


    //The description of this filter
    public String getDescription() {
        return "Image files";
    }
}
